[PATCH] Fix linker flags for Apple
authorMichal Babej <michal.babej@tut.fi>
Thu, 11 Oct 2018 09:19:34 +0000 (12:19 +0300)
committerAndreas Beckmann <anbe@debian.org>
Mon, 4 Feb 2019 23:39:59 +0000 (23:39 +0000)
Gbp-Pq: Name 0001-Fix-linker-flags-for-Apple.patch

CMakeLists.txt
cmake/LLVM.cmake
config.h.in.cmake
lib/CL/devices/common.c

index 00de9005ebfedc49afcaaee916ab7f2aae3d0058..5ce911d9e9616a9d1316a5a63a5cd53f2480b87f 100644 (file)
@@ -647,14 +647,20 @@ set(ENABLE_SPIRV ${SPIRV} CACHE INTERNAL "SPIR-V enabled" FORCE)
 
 ######################################################################################
 
+# fully device-side printf on devices which support it (only CPU backend ATM), disabled by default.
+# this requires 128bit integer support because of the code in "errol" float-to-string conversion routine
+# the output is not 100% compatible with glibc's printf (%f with large argument prints zeroes after
+# last significant digit - 16-18th digit or so, unlike glibc which prints digits up to decimal point).
 if(CLANG_HAS_RTLIB_128)
   option(ENABLE_POCL_FLOAT_CONVERSION "Enable use of pocl's own float-to-decimal conversion code in OpenCL printf(). Defaults to OFF (uses snprintf from C library). Requires compiler-rt." OFF)
 else()
-  set(ENABLE_POCL_FLOAT_CONVERSION OFF CACHE INTERNAL "rtlib")
+  set(ENABLE_POCL_FLOAT_CONVERSION OFF CACHE INTERNAL "pocl's own float-to-decimal conversion code")
 endif()
 
 unset(RTLIB_FLAG)
 if(ENABLE_POCL_FLOAT_CONVERSION)
+  # force link with Clang; otherwise not needed on x86 but in this case we need rtlib
+  set(LINK_WITH_CLANG ON CACHE INTERNAL "Link using Clang")
   set(RTLIB_FLAG "-DENABLE_POCL_FLOAT_CONVERSION")
 endif()
 
@@ -696,21 +702,25 @@ if(UNIX)
     # MacOS ld outputs useless warnings like
     # ld: warning: -macosx_version_min not specificed, assuming 10.7
     # suppress them with -w.
-    set(DEFAULT_HOST_LD_FLAGS "-dylib -w -lm")
+    if(LINK_WITH_CLANG)
+      set(DEFAULT_HOST_LD_FLAGS "-dynamiclib -w -lm")
+    else()
+      set(DEFAULT_HOST_LD_FLAGS "-dylib -w -lm")
+    endif()
   elseif(ANDROID_COMPILER)
     set(DEFAULT_HOST_LD_FLAGS "-L/system/lib/ -shared -ldl -lc -lm /system/lib/crtbegin_so.o /system/lib/crtend_so.o")
   else()
-    if(ENABLE_POCL_FLOAT_CONVERSION)
-      set(DEFAULT_HOST_LD_FLAGS "-shared -lm --rtlib=compiler-rt")
-    else()
-      set(DEFAULT_HOST_LD_FLAGS "-shared -lm")
-    endif()
+    set(DEFAULT_HOST_LD_FLAGS "-shared -lm")
   endif()
   set(LIBMATH "-lm")
 elseif(WIN32)
   set(LIBMATH)
 endif()
 
+if(LINK_WITH_CLANG AND (CLANG_HAS_RTLIB_128 OR CLANG_HAS_RTLIB))
+  set(DEFAULT_HOST_LD_FLAGS "${DEFAULT_HOST_LD_FLAGS} --rtlib=compiler-rt")
+endif()
+
 ######################################################################################
 
 if(UNIX)
@@ -1474,6 +1484,7 @@ if (OCS_AVAILABLE)
   MESSAGE(STATUS "")
   MESSAGE(STATUS "CLANG_HAS_RTLIB: ${CLANG_HAS_RTLIB}")
   MESSAGE(STATUS "CLANG_HAS_RTLIB_128: ${CLANG_HAS_RTLIB_128}")
+  MESSAGE(STATUS "LINK_WITH_CLANG: ${LINK_WITH_CLANG}")
   MESSAGE(STATUS "CLANG_MARCH_FLAG: ${CLANG_MARCH_FLAG}")
   MESSAGE(STATUS "CLANG_TARGET_OPTION: ${CLANG_TARGET_OPTION}")
   MESSAGE(STATUS "LLVM_VERSION: ${LLVM_VERSION}")
index de841b0942857ae313cd528fd14fa70e7eac582f..0b7b32c89a338d8594b6afcb2c16b52d4cc2fb11 100644 (file)
@@ -296,6 +296,7 @@ if(NOT DEFINED LLVM_SPIRV)
     message(STATUS "Found llvm-spirv: ${LLVM_SPIRV}")
   endif()
 endif()
+
 ####################################################################
 
 # try compile with any compiler (supplied as argument)
@@ -452,7 +453,7 @@ endif()
 ####################################################################
 ####################################################################
 
-if(NOT DEFINED CLANG_HAS_RTLIB)
+if(NOT DEFINED LINK_WITH_CLANG)
 
   set(RT128 OFF)
   set(RT64 OFF)
@@ -483,6 +484,17 @@ if(NOT DEFINED CLANG_HAS_RTLIB)
   set(CLANG_HAS_RTLIB ${RT64} CACHE INTERNAL "Clang's compiler-rt available with 64bit types")
   set(CLANG_HAS_RTLIB_128 ${RT128} CACHE INTERNAL "Clang's compiler-rt available with 128bit types")
 
+  if(LLVM_OLDER_THAN_5_0)
+    if(X86)
+      set(LINK_WITH_CLANG OFF CACHE INTERNAL "Link using Clang")
+    else()
+      set(LINK_WITH_CLANG ON CACHE INTERNAL "Link using Clang")
+    endif()
+  else()
+    # on LLVM 5.0+ we use the library API directly instead of forking
+    set(LINK_WITH_CLANG ON CACHE INTERNAL "Link using Clang")
+  endif()
+
 endif()
 
 ####################################################################
index 5b7b758b00e8416369bea5dd77f7f81807211542..a4d587372e4f083d5eb84c96e0e444a8e3697038 100644 (file)
@@ -9,9 +9,6 @@
 
 #define CLANG "@CLANG@"
 
-#cmakedefine CLANG_HAS_RTLIB
-#cmakedefine CLANG_HAS_RTLIB_128
-
 #define CLANG_RESOURCE_DIR "@CLANG_RESOURCE_DIR@"
 
 /* clang++ executable */
 
 #define LINK_COMMAND "@LINK_COMMAND@"
 
+#cmakedefine LINK_WITH_CLANG
+
 /* Defined to greatest expected alignment for extended types, in bytes. */
 #define MAX_EXTENDED_ALIGNMENT @MAX_EXTENDED_ALIGNMENT@
 
index 6dc18d0e97233c15ca6b8fedebcf3e0640069e94..56e060ce00887fbed44f568ad3a7ba4b90fe197a 100644 (file)
@@ -198,7 +198,7 @@ llvm_codegen (const char* tmpdir, cl_kernel kernel, cl_device_id device,
   char *const args1[]
 #ifndef POCL_ANDROID
 /* use Clang as linker, when compiler-rt is available and needed */
-#if defined(ENABLE_POCL_FLOAT_CONVERSION) || defined(CLANG_HAS_RTLIB)
+#if defined(LINK_WITH_CLANG)
       = { CLANG,
 #else
       = { LINK_COMMAND,